import axios from "axios";
import baseConfig from "../../config";


function http(config){

  // config
  const instance = axios.create({
    baseURL: baseConfig.getApiUrl(),
    timeout: 1000,
    headers: {'X-Custom-Header': 'foobar'}
  });
  
  instance.interceptors.request.use(function (config) {

      // console.log(config);

      // console.log("发起请求前");

        // Do something before request is sent
        return config;
      }, function (error) {
        // Do something with request error
        return Promise.reject(error);
      });
    
    // Add a response interceptor
    instance.interceptors.response.use(function (response) {
      console.log("发起请求后");

        // Any status code that lie within the range of 2xx cause this function to trigger
        // Do something with response data
        return response;
      }, function (error) {
        console.log("发起请求后错误执行");
        // Any status codes that falls outside the range of 2xx cause this function to trigger
        // Do something with response error
        return Promise.reject(error);
      });

      return instance;
}

export default http;